home *** CD-ROM | disk | FTP | other *** search
/ Shareware Super Platinum 8 / Shareware Super Platinum 8.iso / mac / PROGTOOL / FGL304E.ZIP;1 / EXPAS.ARJ / FGDOC / EXAMPLES / PASCAL / CC-01.ASM < prev    next >
Encoding:
Assembly Source File  |  1994-01-24  |  4.3 KB  |  109 lines

  1. ;****************************************************************************
  2. ;
  3. ; int1C -- A assembly language template callable from Turbo Pascal to define
  4. ;          an interrupt handler for INT 1C (if flag=1) or to replace the
  5. ;          original INT 1C handler (if flag=0).
  6. ;
  7. ; Prototype:  procedure int1C(flag : integer);
  8. ;
  9. ;****************************************************************************
  10.  
  11.            EXTRN   status1:word  ; TP global variable for button 1 status
  12.            EXTRN   status2:word  ; TP global variable for button 2 status
  13.            EXTRN   fg_button:far ; Fastgraph routine
  14.  
  15. int1C_TEXT SEGMENT byte public 'CODE'
  16.            ASSUME  cs:int1C_TEXT
  17.  
  18. int1C_CS   dw      ?             ; holds original INT 1C segment address
  19. int1C_IP   dw      ?             ; holds original INT 1C offset
  20. orig_DS    dw      ?             ; holds original data segment
  21.  
  22. int1C      PROC    far
  23.            PUBLIC  int1C
  24.  
  25.            push    bp            ; save caller's BP register
  26.            mov     bp,sp         ; make BP point to argument list
  27.  
  28.            mov     dx,[bp+6]     ; get the flag parameter
  29.            or      dx,dx         ; replace the old interrupt handler?
  30.            jz      replace       ; yes, branch to that processing
  31.  
  32. ; define a new handler for INT 1C
  33.  
  34. define:    mov     ax,ds         ; put current data segment in AX
  35.            mov     cs:orig_DS,ax ; save it in the control information area
  36.  
  37.            mov     al,1Ch        ; interrupt vector to save
  38.            mov     ah,53         ; function 53: get interrupt vector
  39.            int     21h           ; get the interrupt vector
  40.            mov     cs:int1C_CS,es; save the segment
  41.            mov     cs:int1C_IP,bx; save the offset
  42.  
  43.            push    ds            ; save our DS register
  44.            mov     dx,offset handler ; get offset of interrupt handler
  45.            mov     ax,seg handler; get segment of interrupt handler
  46.            mov     ds,ax         ; put it in DS
  47.            mov     al,1Ch        ; interrupt vector to change
  48.            mov     ah,37         ; function 37: set interrupt vector
  49.            int     21h           ; change the INT 1C vector to our handler
  50.            pop     ds            ; restore our DS register
  51.  
  52.            jmp     short return  ; return to the caller
  53.  
  54. ; replace the original handler for INT 1C
  55.  
  56. replace:   push    ds            ; save our DS register
  57.            mov     dx,cs:int1C_IP; put original INT 1C offset in DX
  58.            mov     ds,cs:int1C_CS; put original INT 1C segment in DS
  59.            mov     ah,37         ; function 37: set interrupt vector
  60.            mov     al,1Ch        ; interrupt vector 1C
  61.            int     21h           ; restore original INT 1C vector
  62.            pop     ds            ; restore our DS register
  63.  
  64. return:    xor     ax,ax         ; in case int1C was called as a function
  65.            pop     bp            ; restore our BP register
  66.            ret     2             ; return to the caller
  67.  
  68. int1C      ENDP
  69.  
  70.  
  71. handler    PROC    far           ; interrupt handler that replaces INT 1C
  72.  
  73.            cli                   ; disable interrupts while handler is active
  74.            push    ax            ; save registers that may be altered
  75.            push    bx
  76.            push    cx
  77.            push    dx
  78.            push    di
  79.            push    si
  80.            push    ds
  81.            push    es
  82.  
  83.            mov     ds,cs:orig_DS ; retrieve the original data segment
  84.  
  85.            mov     ax,1          ; use joystick 1
  86.            push    ax            ; pass joystick number to button routine
  87.            call    fg_button     ; AX = button status for joystick 1
  88.            or      status1,ax    ; update the status variable for joystick 1
  89.  
  90.            mov     ax,2          ; use joystick 2
  91.            push    ax            ; pass joystick number to button routine
  92.            call    fg_button     ; AX = button status for joystick 2
  93.            or      status2,ax    ; update the status variable for joystick 2
  94.  
  95.            pop     es            ; restore altered registers
  96.            pop     ds
  97.            pop     si
  98.            pop     di
  99.            pop     dx
  100.            pop     cx
  101.            pop     bx
  102.            pop     ax
  103.            iret                  ; return from the interrupt routine
  104.  
  105. handler    ENDP
  106.  
  107. int1C_TEXT ENDS
  108.            END
  109.